<template>
  <section class="page">
    <headerbar>
      {{title}}
<!--      <broadcastDetail v-if="typeof detail.newsContent !='undefined' && tools.NotIsNull(detail.newsContent.ttsOssUrl)" :detail="detail"/>-->
    </headerbar>
    <fetchData  class="bg-white" :loading="isLoading" :data="detail"></fetchData>
    <section class="bg-white" v-if="preData.createTime">
      <section class="detail">
        <h1 class="title">{{preData.title}}</h1>
<!--        <p class="date no-wrap">来源：{{preData.source || '未知'}} <span class="float-right">时间：{{tools.formatDate(preData.createTime)}}</span></p>-->
        <p class="color-red pdh-2 pdv-1 shortTitle">{{preData.shortTitle}}</p>
        <p class="line"></p>
        <div class="cont-text" v-saveImage="saveImage" v-if="detail.newsContentExt" v-html="makeTargetToWindowOpen(detail.newsContentExt.contents)"></div>

        <fileDownloadComponent :contentId="detail.newsContent.id"></fileDownloadComponent>

        <p class="pdv-2"></p>
<!--        <viewsUpsComponent v-if="detail.newsContent && isUpsComponent"></viewsUpsComponent>-->
      </section>
    </section>
    <abnormal  @refresh="loadData" v-if="abnormal"></abnormal>
    <noData :loading="isLoading" :data="detail" v-else-if="!isLoading && detail.length <= 0"></noData>
<!--      <img-->
<!--        src="static/images/dangjian/home/water-logo-comment.png"-->
<!--        alt=""-->
<!--      />-->
<!--      <div class="pdv-4"></div>-->
<!--    </div>-->
    <!--<liveMsgComponent v-if="preData.id" :detail="preData" :contentId="preData.id" :comments="preData.comments"></liveMsgComponent>-->
    <readScore v-if="detail.newsContent" :_contentId="detail.newsContent.id" :type="1"></readScore>
  </section>
</template>

<script>
  import _ from 'lodash'
  import fileDownloadComponent from '@/components/common/fileDownloadComponent.vue'
  import viewsUpsComponent from '@/components/common/viewsUpsComponent'
  import {makeTargetToWindowOpen} from '@/utils/H5Adapt'
  export default {
    components: {viewsUpsComponent, fileDownloadComponent},
    name: 'myCommonQuestionDetail',
    data () {
      return {
        abnormal: false,
        preData: {},
        detail: {},
        shareDialogInstance: null,
        isLoading: true,
        title: '红云头条',
        chanelId:'',
        getDict:[],
        allowProhibit:true,//是否启用下方输入框 true 允许 false 不允许
        isUpsComponent:true,//是否展示点赞量和阅读量 true 展示 false 不展示
        isXommentoff: true,//是否需要红线 true 需要 false 不需要
      }
    },
    watch:{
      $route(to,from){
        this.loadData ()
      }
    },
    created () {
      this.isUpsComponent = this.$route.params.isUpsComponent === false ? false : true
      this.allowProhibit = this.$route.params.allowProhibit === false ? false : true
      this.$store.state.flagType = 1
      this.title = this.$route.params.title
      if (this.$route.query.channelName) {
        this.title = this.$route.query.channelName
      }else if (this.$route.params.channelName) {
        this.title = this.$route.params.channelName
      }
      // this.chanelId = this.$route.params.chanelId || this.$route.query.chanelId || '';

      this.loadData()
      console.log('---------------this.$route.params.id=', this.$route.params.id)
      // this.like(this.$route.params.id)//阅读量+1请求
    },
    beforeDestroy () {
      // this.log()
    },
    methods: {
      makeTargetToWindowOpen,
      /*log (actionType) {
        let type = actionType || 5 //操作取值范围： 1 点赞、2 收藏、3 评论、4 转发、5 浏览
        console.log('type',type);
        this.logEvent(type, {//所有的标签都可以使用相对应的中文
          'content_type': 1, //内容类型 1 文字、2 音频、3 视频
          'area_type': this.preData.qyflTags || '',//区域分类 1 贵州省、2 贵阳市、3 观山湖区、4 南明区、5 云岩区、6 白云区、7 花溪区、8 乌当区、9 清镇市、10 开阳县、11 息烽县
          'theme_type':this.preData.ztflTags || '', //主题分类 1 本地动态、2 政策解读、3 人事动态、4 警钟长鸣、5 党务知识、6 动态、7 示范带、8 身边好党员、9 党史上的今天
          'event_type': this.preData.sjflTags || '',//事件分类 1 召开会议、2 考察调研、3 主持会议、4 致辞、5 出席、6 发展、7 发表、8 建设、9 讲话
          'arrangement_type': this.preData.ccflTags || '',//层次分类 中央、省级、市级、区县级
          'soure_type': this.preData.lyflTags || '',//来源分类 1 共产党员网、2 人民网、3 新华社、4 人民日报、5 贵州日报、6 贵阳日报、7 贵阳党建网、8 贵阳市政府网、9 贵阳市人力资源网、10天眼新闻、11 知知贵阳、12 贵州改革
          'character_type': this.preData.rwflTags || '', //人物分类 1 习近平、2 李克强、3 孙志刚、4 谌贻琴、5 赵德明、6 陈晏、7 滕伟华
          'other_type': 0,//其他分类
          'content_id': this.preData.id, //内容ID
          'category_type':this.preData.categoryTags || "",//分类 1 农村 2 城市社区 3 机关 4 学校 5 国有企业 6 非公有制经济组织和社会组织 7 其他
          'content_title': this.preData.title, //内容标题
          'publish_time': this.preData.publishTime,
        } )
      },*/
      /* showShareDialog () {
        if (!this.shareDialogInstance) {
          this.shareDialogInstance = this.$createShareDialog({
            $props: {
              newsId: this.$route.params.id || this.preData.id,
              newsTitle: this.preData.title,
              type: 0,
              listPic: this.detail.newsContent.listPic
            }
          })
        }
        this.shareDialogInstance.show()
      }, */
      saveImage (src) {
        this.$createActionSheet({
          title: '',
          active: 0,
          data: [
            {
              content: '保存图片'
            }
          ],
          onSelect: (item, index) => {
            console.log('onSelect', src)
            if (window.android && window.android.downloadFile) {
              window.android.downloadFile(src, `新闻图片${Date.now()}.png`)
            }
          }
        }).show()
      },
      loadData () {
        this.abnormal = false
        this.isLoading = true
        let id = this.$route.params.id
        // this.fetchService.contentPageDetail(id).then(res => {//老接口
        this.fetchService.contentDetailNew(id).then(res => {//新接口
          if (res.code === 0) {
            this.detail = res.data

            this.chanelId = this.detail.newsContent.channelId;
            /*if(this.isComment){
              this.isCommentTag()
            }*/

            // 真实的阅读量
            this.$store.state.newsDetail = _.extend(this.$store.state.newsDetail, this.detail.newsContent)
            this.$store.state.newsDetail.detail = this.detail
            this.preData = this.detail.newsContent
            this.$store.state.newsDetail.views = ++this.detail.newsContent.views
            console.log('this.preDatathis.preData',this.preData);
            this.like(id)//阅读量+1请求
            // this.log()
            /*if (this.detail.newsContentExt) {
              this.historyAdd()
            }*/
          }
          // this.like(id)//阅读量+1请求
          if (res.code == 444) {
            this.abnormal = true
          }
          this.isLoading = false
        })
      },
      isCommentTag(){
        this.getDictValue()
        console.log('this.isComment',this.isComment);
        let data={
          catKey:'HYTT',
          treeKey:'BNPLDLM'
        }
        this.fetchService.dictValue(data).then(res => {
          console.log('this.fetchService.dictValue',res.data)
          if(res.code === 0){
            res.data.forEach(item=>{
              console.log('item.key',item.key);
              console.log(' this.chanelId', this.chanelId);
              if(item.key == this.chanelId){
                this.isComment = item.value == 'true' ? true: false
                this.isXommentoff = item.value == 'true' ? true: false
                console.log('this.isCommentaaaaaaaaaaaaaa',this.isComment);
              }
            })
          }
        })
      },
    // 添加到我的足迹
      historyAdd () {
        let data = {
          contentId: this.detail.newsContentExt.contentId,
          newsType: 0,  // 新闻类型(0图文;1长视频;2音频;3短视频)
        }
        this.fetchService.historyAdd(data).then((res) => {
        })
      },
      like (id) {
        let params = {
          contentId: id,
          type: 1
        }
        this.fetchService.updateCount(params).then(res => {
        })
      },
      //请求字典值
      async getDictValue () {
        let data={
          catKey:'HYTT',
          treeKey:'BNPLDLM'
        }
       await this.fetchService.dictValue(data).then(res => {
          console.log('this.fetchService.dictValue',res.data)
          if(res.code === 0){
            this.getDict=res.data
          }
        })
      },
    }
  }
</script>

<style lang="scss" scoped>
  @import "@/common/stylus/moon.scss";
</style>
